package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GradeTable;
import com.ruoyi.system.service.IGradeTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 选手成绩录入Controller
 *
 * @author zhangjinlei
 * @date 2022-04-26
 */
@RestController
@RequestMapping("/system/table")
public class GradeTableController extends BaseController
{
    @Autowired
    private IGradeTableService gradeTableService;

    /**
     * 查询选手成绩录入列表
     */
    @PreAuthorize("@ss.hasPermi('system:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(GradeTable gradeTable)
    {
        startPage();
        List<GradeTable> list = gradeTableService.selectGradeTableList(gradeTable);
        return getDataTable(list);
    }

    /**
     * 查询国家排行榜
     */

    @GetMapping("/rankingsList")
    public TableDataInfo cpRankingList(GradeTable gradeTable)
    {
        startPage();
        List<GradeTable> cpRankingList = gradeTableService.selectCpRankingList(gradeTable);
        return getDataTable(cpRankingList);
    }

    /**
     * 导出选手成绩录入列表
     */
    @PreAuthorize("@ss.hasPermi('system:table:export')")
    @Log(title = "选手成绩录入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GradeTable gradeTable)
    {
        List<GradeTable> list = gradeTableService.selectGradeTableList(gradeTable);
        ExcelUtil<GradeTable> util = new ExcelUtil<GradeTable>(GradeTable.class);
        util.exportExcel(response, list, "选手成绩录入数据");
    }

    /**
     * 获取选手成绩录入详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:table:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gradeTableService.selectGradeTableById(id));
    }

    /**
     * 新增选手成绩录入
     */
    @PreAuthorize("@ss.hasPermi('system:table:add')")
    @Log(title = "选手成绩录入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GradeTable gradeTable)
    {
        return toAjax(gradeTableService.insertGradeTable(gradeTable));
    }

    /**
     * 修改选手成绩录入
     */
    @PreAuthorize("@ss.hasPermi('system:table:edit')")
    @Log(title = "选手成绩录入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GradeTable gradeTable)
    {
        return toAjax(gradeTableService.updateGradeTable(gradeTable));
    }

    /**
     * 删除选手成绩录入
     */
    @PreAuthorize("@ss.hasPermi('system:table:remove')")
    @Log(title = "选手成绩录入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gradeTableService.deleteGradeTableByIds(ids));
    }
}
